


//
//  ZHUserAccount.swift
//  999999新浪微博
//
//  Created by 陈华 on 15/12/21.
//  Copyright © 2015年 华锐. All rights reserved.
//

import UIKit

class ZHUserAccount: NSObject, NSCoding{
    var access_token: String?//<访问令牌
    var uid: String?//<用户UID
    var expires_in = 0{//<访问令牌生命周期
        didSet{
            expires_inDate = NSDate(timeIntervalSinceNow: Double(expires_in))
        }
    }
    
    var expires_inDate:NSDate?//<访问令牌到期时间
    
    
    ///重载构造函数
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    ///从写description
    override var description: String{
        get {
            return "access_token: \(access_token), uid: \(uid), expires_in: \(expires_in),expires_inData\(expires_inDate)"
        }
    }
    
    //MARK: - 归档
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(access_token, forKey: "access_token")
        aCoder.encodeObject(uid, forKey: "uid")
        aCoder.encodeObject(expires_in, forKey: "expires_in")
        aCoder.encodeObject(expires_inDate, forKey: "expires_inDate")
    }
    required init?(coder aDecoder: NSCoder) {
     access_token =  aDecoder.decodeObjectForKey("access_token") as? String
      uid = aDecoder.decodeObjectForKey("uid") as? String
      expires_in = aDecoder.decodeObjectForKey("expires_in") as! Int
      expires_inDate = aDecoder.decodeObjectForKey("expires_inDate") as? NSDate
    }
}















